var userInfo;

getUserInfo();
function getUserInfo() {
    $.ajax({
        type: "post",
        async: false,//异步，如果等于false 那么就是同步
        url: cochoApp.baseUrl + "/admin/uc/getUserInfoByCurrentId.do?token=" + cochoApp.getTokenByStorage(),
        dataType: "json",
        data: "",
        success: function (data) {
            if (data != null && data.statusCode == cochoApp.SUCCESS) {
                if (data.dataRows.length > 0) {
                    userInfo = data.dataRows[0];
                    $("#userId").val(userInfo.userId);
                    $("#userName").val(userInfo.username);
                } else {
                    cochoAlert.notificationsWarn("暂无用户信息！");
                    return false;
                }
            } else {
                cochoAlert.notificationsWarn("获取会员信息失败！");
                return false;
            }
        },
        error: function (data) {
            cochoAlert.notificationsWarn(cochoErrorMessage.server_error_connect_admin);
            return false;
        }
    });
}

function updatePassword() {
    var result = checkNullAndWarnHasNull();
    if(result == true){
        var userId = $("#userId").val();
        var userPassword = $("#userPassword").val();
        var newPassword = $("#newPassword").val();
        if(newPassword.length < 6){
            alert("对不起，新密码长度不能低于六位！");
            return false;
        }

        var checkPassword = $("#checkPassword").val();
        if(checkPassword.length < 6){
            alert("对不起，确认密码长度不能低于六位！");
            return false;
        }

        if(newPassword != checkPassword){
            cochoAlert.notificationsWarn("两次密码输入不一致！");
            return false;
        }

        var paramData = {"userId":userId,"userPassword": userPassword,"mobilePhone":newPassword,"token": cochoApp.getTokenByStorage()};
        $.ajax({
            type: "post",
            async: true,//异步，如果等于false 那么就是同步
            url: cochoApp.baseUrl + "/admin/uc/updateUserPassWord.do",
            dataType: "json",
            data: paramData,
            success: function (data) {
                if (data != null && data.statusCode == cochoApp.SUCCESS) {
                    cochoAlert.notificationsWarn(data.statusMsg);
                }else if(data != null && data.statusCode == cochoApp.FAIL){
                    cochoAlert.notificationsWarn(data.statusMsg);
                    return false;
                } else {
                    cochoAlert.notificationsWarn(data.statusMsg);
                    return false;
                }
            },
            error: function (data) {
                alert(cochoErrorMessage.server_error_connect_admin);
                return false;
            }
        });
    }

}

